function a(ele){return document.querySelector(ele)}

//ajax_get
function ajax_get(url,str){
    return new Promise((resolve,reject)=>{
        let xhr=new XMLHttpRequest()
        xhr.open("get",url,true)
        xhr.send()
        xhr.onreadystatechange=()=>{
            if(xhr.readyState === 4 && xhr.status === 200){
                resolve(xhr.responseText)
            }
        }
    })
}
//ajax_post
function ajax_post(url,str){
    return new Promise((resolve,reject)=>{
        let xhr=new XMLHttpRequest()
        xhr.open("post",url,true)
        xhr.setRequestHeader('content-type','application/x-www-form-urlencoded')
        xhr.send(str)
        xhr.onreadystatechange=()=>{
            if(xhr.readyState === 4 && xhr.status === 200){
                resolve(xhr.responseText)
            }
        }
    })
}

//点击添加商品按钮，添加商品
$("#add_btn").on("click",function(){
    let str="product_name="+$("#product_name").val()+"&product_price="+$("#product_price").val()+"&product_num="+$("#product_num").val()+"&product_src="+$("#product_src").val()+"&product_size="+$("#product_size").val()+"&product_type="+$("#product_type").val()
    console.log(str)
    ajax_post("./add_product_post.php",str).then(result=>{
        console.log(result)
    })
    a("#form").reset()
})

a("#quit").onclick=function(){
    window.open("http://localhost/mogujie/home-page.html")
}